package com.yang.Offer;

public class Offer22 {
}
class Offer22Solution {
    // 快慢指针
    // 快指针先走K步 然后两个指针一起走 快指针到底 慢指针的位置就是倒数第k
    public SolutionOffer06.ListNode getKthFromEnd(SolutionOffer06.ListNode head, int k) {
        SolutionOffer06.ListNode slow = head;
        SolutionOffer06.ListNode fast = head;
        for(int i = 0; i < k; i++){
            fast = fast.next;
        }
        while(fast != null){
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
